import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:getx_tutorial/app/modules/login/login_page.dart';
import 'package:getx_tutorial/app/routes/app_pages.dart';

class RoutePage extends GetView {
  @override
  Widget build(BuildContext context) {

    return Scaffold(
      appBar: AppBar(
        title: Text('路由'),
        centerTitle: true,
      ),

      body: SafeArea(
        child: ListView(
          children: [
            ListTile(
              title: Text('导航 - 类对象'),
              subtitle: Text('Get.to(LoginPage())'),
              trailing: Icon(Icons.chevron_right_outlined),
              onTap: () {
                Get.to(LoginPage());
              }
            ),
            ListTile(
              title: Text('导航 - 命名路由'),
              subtitle: Text("Get.to('/login')"),
              trailing: Icon(Icons.chevron_right_outlined),
              onTap: () {
                Get.toNamed(Routes.LOGIN);
              }
            ),
            ListTile(
              title: Text('导航 - 清除上一个'),
              subtitle: Text('Get.off(LoginPage())'),
              trailing: Icon(Icons.chevron_right_outlined),
              onTap: () {
                Get.off(LoginPage());
              }
            ),
            ListTile(
              title: Text('导航 - 清除所有'),
              subtitle: Text('Get.offAll(LoginPage())'),
              trailing: Icon(Icons.chevron_right_outlined),
              onTap: () {
                Get.offAll(LoginPage());
              }
            ),

            ListTile(
              title: Text('导航 - 传参'),
              subtitle: Text('Get.toNamed("/home/:type")'),
              trailing: Icon(Icons.chevron_right_outlined),
              onTap: () {
                Get.toNamed("/home/toutiao");
              }
            ),

            ListTile(
              title: Text('导航 - 传参'),
              subtitle: Text('Get.toNamed("/news?id=123")'),
              trailing: Icon(Icons.chevron_right_outlined),
              onTap: () {
                Get.toNamed(Routes.NEWS+"?id=123");
              }
            ),

            ListTile(
              title: Text('导航 - 传参+返回值'),
              subtitle: Text('Get.toNamed("/news", arguments: 666)'),
              trailing: Icon(Icons.chevron_right_outlined),
              onTap: () async {
                var res = await Get.toNamed(Routes.NEWS, arguments: 666);
                print('Back 返回参数：'+res['success'].toString());
              }
            ),

            ListTile(
              title: Text('导航 - 嵌套路由'),
              subtitle: Text('Get.toNamed("/state")'),
              trailing: Icon(Icons.chevron_right_outlined),
              onTap: () {
                Get.toNamed(Routes.STATE);
              }
            ),
            ListTile(
              title: Text('导航 - 嵌套路由 - 子路由1'),
              subtitle: Text('Get.toNamed("/state/obx")'),
              trailing: Icon(Icons.chevron_right_outlined),
              onTap: () {
                Get.toNamed(Routes.STATE+Routes.OBX);
                // Get.toNamed("/state/obx");
              }
            ),

            ListTile(
              title: Text('导航 - 嵌套路由 - 子路由2'),
              subtitle: Text('Get.toNamed("/state/getx")'),
              trailing: Icon(Icons.chevron_right_outlined),
              onTap: () {
                // Get.toNamed(Routes.GETX);
                Get.toNamed("/state/getx");
              }
            ),

            ListTile(
              title: Text('导航 - snackbar'),
              subtitle: Text('Get.snacker("标题","消息", ...)'),
              trailing: Icon(Icons.chevron_right_outlined),
              onTap: () {
                Get.snackbar(
                  "标题", 
                  "已发送",
                  snackPosition: SnackPosition.BOTTOM,
                  showProgressIndicator: true
                );
              }
            ),
            ListTile(
              title: Text('导航 - defaultDialog'),
              subtitle: Text('Get.defaultDialog(...)'),
              trailing: Icon(Icons.chevron_right_outlined),
              onTap: () {
                Get.defaultDialog(
                  title: "标题", 
                  content: Column(
                    children: [
                      Text('这里是内容')
                    ],
                  ),
                  textConfirm: "确认",
                  textCancel: "取消",
                  onConfirm: () => Get.back()
                );
              }
            ),

            ListTile(
              title: Text('导航 - bottomSheet'),
              subtitle: Text('Get.bottomSheet(...)'),
              trailing: Icon(Icons.chevron_right_outlined),
              onTap: () {
                Get.bottomSheet(
                  Container(
                    color: Colors.white,
                    child: Wrap(
                      children: [
                        ListTile(
                          leading: Icon(Icons.music_note),
                          title: Text('音乐'),
                          onTap: () {}
                        ),
                        ListTile(
                          leading: Icon(Icons.videocam),
                          title: Text('视频'),
                          onTap: () {}
                        ),
                      ],
                    ),
                  )
                );
              }
            ),

            ListTile(
              title: Text('导航 - 中间件'),
              subtitle: Text('Get.toNamed("/mine")'),
              trailing: Icon(Icons.chevron_right_outlined),
              onTap: () {
                Get.toNamed(Routes.MINE);
              }
            ),

            ListTile(
              title: Text('导航 - 中间件 - 子路由'),
              subtitle: Text('Get.toNamed("/mine/recharge")'),
              trailing: Icon(Icons.chevron_right_outlined),
              onTap: () {
                Get.toNamed(Routes.MINE+Routes.RECHARGE);
              }
            ),

            ListTile(
              title: Text('导航 - 多个中间件'),
              subtitle: Text('Get.toNamed("/mine/vip")'),
              trailing: Icon(Icons.chevron_right_outlined),
              onTap: () {
                Get.toNamed(Routes.MINE+Routes.VIP);
              }
            ),

            ListTile(
              title: Text('导航 - 未知路由'),
              subtitle: Text('Get.toNamed("/abc")'),
              trailing: Icon(Icons.chevron_right_outlined),
              onTap: () {
                Get.toNamed("/abc");
              }
            ),
          ],
        )
      )
    );
  }
}